<!-- 选择下拉框 -->
<template>
  <a-tree-select
    allow-clear
    tree-default-expand-all
    :placeholder="placeholder"
    :value="value || undefined"
    :tree-data="data"
    :dropdown-style="{ maxHeight: '360px', overflow: 'auto' }"
    @update:value="updateValue"
  />
</template>

<script lang="ts" setup>
  import { Category } from '@/api/content/category/model';

  const emit = defineEmits<{
    (e: 'update:value', value?: number): void;
  }>();

  withDefaults(
    defineProps<{
      value?: number;
      placeholder?: string;
      data: Category[];
    }>(),
    {
      placeholder: '请选择分类'
    }
  );

  /* 更新选中数据 */
  const updateValue = (value?: number) => {
    emit('update:value', value);
  };
</script>
